<template>
  <div>
    <!-- 搜索条件盒子 -->
    <div>
      <p class="pinformation">搜索条件</p>
      <el-form label-width="90" ref="queryRef" :model="queryParams">
        <el-form-item label="方案编号：" prop="projectCode">
          <el-input
            maxlength="100"
            clearable
            placeholder="请输入方案编号"
            v-model="queryParams.projectCode"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="委托单位：" prop="wtCustomName">
          <el-input
            maxlength="100"
            clearable
            placeholder="请输入委托单位"
            v-model="queryParams.wtCustomName"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="拟开始时间：">
          <el-date-picker
            v-model="dateRange"
            value-format="YYYY-MM-DD"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            style="width: 100%"
          ></el-date-picker>
        </el-form-item>
        <el-row>
          <el-col :span="18">
            <el-form-item label="紧急类型：" prop="degree">
              <el-select
                v-model="queryParams.degree"
                placeholder="请选择紧急类型"
                @change="handleQuery"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in proxy.addListNoLimit(sys_degree)"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-row style="justify-content: center">
              <el-button type="success" @click="handleQuery">搜索</el-button>
              <el-button class="business resetBtn" @click="resetQuery"
                >重置</el-button
              >
            </el-row>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 检测类别列表盒子 -->
    <div>
      <el-row>
        <p class="pinformation">方案列表</p>
        <p class="totalStyle">共 {{ total }} 条数据</p>
      </el-row>
      <el-table ref="mainTableRef" :data="projectList" v-loading="loading" :row-class-name="tableRowClass" @row-click="rowClick">
        <el-table-column label="委托单位" align="center" prop="wtCustomName" />
        <el-table-column label="方案编号" align="center" prop="projectCode" />
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script setup>
import { listPoint } from "@/api/cyCheck/cyGuide";

const { proxy } = getCurrentInstance();
const { sys_degree } = proxy.useDict("sys_degree");

const total = ref(0);
const projectList = ref([]);
const dateRange = ref([]);
const loading = ref(true);

const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    degree: -1,
    getId: props.isRepertory,
  },
});

const { queryParams } = toRefs(data);

//定义参数 已经选中的ITEMID
const props = defineProps({
  isRepertory: {
    type: Number, //参数类型
  },
});

watch(
  () => total.value,
  () => {
    if (total.value) {
      heightParams.value = [{ tableName: "main", bottomHeight: 74 }];
    } else {
      heightParams.value = [{ tableName: "main", bottomHeight: 21 }];
    }
    getTableHeight();
  }
);

const heightParams = ref([{ tableName: "main", bottomHeight: 21 }]);
function getTableHeight() {
  proxy.adaptiveHeight(proxy, heightParams.value);
}

onMounted(() => {
  nextTick(function () {
    getTableHeight();
    window.addEventListener("resize", getTableHeight);
  });
})

onUpdated(() => {
  nextTick(function () {
    getTableHeight();
  });
});

onBeforeUnmount(() => {
  window.removeEventListener("resize", getTableHeight);
});

function getList() {
  loading.value = true;
  listPoint(proxy.addDateRange(queryParams.value, dateRange.value)).then(
    (res) => {
      projectList.value = res.rows;
      total.value = res.total;
      loading.value = false;
    }
  );
}

function handleQuery() {
  queryParams.pageNum = 1;
  getList();
}
function resetQuery() {
  proxy.resetForm("queryRef");
  dateRange.value = [];
  getList();
}

const emit = defineEmits(["getProjctId"])
function rowClick(row) {
  heightBright.value = row.projectId
  emit("getProjctId", row.projectId)
}

const heightBright = ref("")
function tableRowClass({ row }) {
  if (row) {
    if (row.projectId == heightBright.value) {
      return "current-row";
    }
    return "";
  }
}

getList();
</script>
